home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
alpha.arc
/
BSDUNIX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1987-12-22
|
3KB
|
199 lines
/*
FILE: unix.c
Routines: This file contains the following routines:
eihalt()
kbread()
clksec()
tmpfile()
restore()
stxrdy()
disable()
memstat()
filedir()
Written by Mikel Matthews, N9DVG
SYS5 stuff added by Jere Sandidge, K4FUM
*/
#include <stdio.h>
#include <signal.h>
#include <sys/time.h>
#include "global.h"
#include "cmdparse.h"
#include "iface.h"
#include <sys/types.h>
#include <sys/dir.h>
#include <sys/wait.h>
#include "smtp.h"
#include "unix.h"
int asy_attach();
extern struct cmds attab[];
eihalt()
{
}
kbread()
{
int mask;
char c = -1;
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 35;
mask = 1<<0;
select(1, &mask, (int *)NULL, (int *)NULL, &timeout);
if ( mask &= 1<<0 )
{
read(fileno(stdin),&c, 1);
}
return(c);
}
clksec()
{
struct timeval time;
struct timezone zone;
gettimeofday(&time, &zone);
return(time.tv_sec);
}
FILE *
tmpfile()
{
FILE *tmp;
char *mktemp();
char *ptr = "SMTPXXXXXX";
char *name;
name = mktemp(ptr);
if ( ( tmp = fopen(name, "w") ) == NULL)
{
printf("tmpfile: counld not create temp file.\n");
return(NULL);
}
(void) unlink(name);
return ( tmp );
}
restore()
{}
stxrdy()
{return(1);}
disable()
{}
memstat()
{
return(0);
}
/* wildcard filename lookup */
filedir (name, times, ret_str)
char *name;
int times;
char *ret_str;
{
DIR *dirp;
struct direct *dp;
char *ptr;
char *index();
extern char mailqdir[];
/*
* Make sure that the NULL is there incase we don't find anything
*/
ret_str[0] = NULL;
if ( (dirp = opendir(mailqdir)) == NULL ) {
printf("Could not open mail queue (%s)\n", mailqdir);
return;
}
else {
for ( dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
if ( ( ptr = index(dp->d_name, '.')) == NULL) {
continue;
}
else {
ptr++;
if ( strncmp(ptr, "wrk", 3) != 0) {
continue;
}
else {
strncpy(ret_str, dp->d_name, dp->d_namlen);
ret_str[dp->d_namlen] = '\0';
break;
}
}
}
}
}
/* checks the time then ticks and updates ISS */
static int clkval = 0;
void
check_time()
{
int32 iss();
if(clkval != clksec()){
clkval = clksec();
tick();
(void)iss();
}
}
getds()
{
return (0);
}
audit(){}
doshell(argc, argv)
char **argv;
{
register int pid, pid1, i, (*savi)();
union wait rc;
char str[128];
for (i = 1; i < argc; i++) {
strcat(str, argv[i]);
strcat(str, " ");
}
if ((pid = fork()) == 0) {
if (argc > 1)
(void)execl("/bin/sh", "sh", "-c", str, 0);
else
(void)execl("/bin/sh", "/bin/sh", (char *)0,(char *)0,0);
}
savi = signal(SIGINT, SIG_IGN);
while ((pid1 = wait(&rc)) != pid && pid1 != -1)
;
signal(SIGINT, savi);
return (rc.w_status);
}
dodir(argc, argv)
char **argv;
{
register int pid, pid1, i, (*savi)();
union wait rc;
char str[128];
strcpy(str, "ls -l ");
for (i = 1; i < argc; i++) {
strcat(str, argv[i]);
strcat(str, " ");
}
if ((pid = fork()) == 0)
system(str);
savi = signal(SIGINT, SIG_IGN);
while ((pid1 = wait(&rc)) != pid && pid1 != -1)
;
signal(SIGINT, savi);
return (rc.w_status);
}